package com.liuhung.ash.security.service;

import java.util.ArrayList;
import java.util.List;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.liuhung.base.page.BasePage;
import com.liuhung.base.service.BaseService;
import com.liuhung.ash.security.dao.CategoryDao;
import com.liuhung.ash.security.entity.Category;

/**
 * 
 * <br>
 * <b>功能：</b>CategoryService<br>
 */
@Service("categoryService")
@Transactional
public class CategoryService<T> extends BaseService<Category> {
	@Autowired
    private CategoryDao<Category> dao;
	public CategoryDao<Category> getDao() {
		return dao;
	}
	/**
	 * 根据父id获取list
	 * @param str
	 * @return
	 */
	public List<Category> queryByPid(Object str)
	{
		return dao.queryChild(str);
	}
	
	public List<Category> queryRoot(Object str){
		return dao.queryRoot(str);
	}
	
	public List<Category> queryAllChildrenByPid(Object str)
	{
		List<Category> ts = new ArrayList<Category>();
		List<Category> ts2 = (List<Category>) queryByPid(str);
		for(Category t:ts2)
		{
			ts.add(t);
			List<Category> ts3 =queryByPid(t.getId());
			if(ts3.size()>0)
			{
				ts.addAll(queryAllChildrenByPid(t.getId()));
			}
		}
		return ts;
	}
	public List<Category> queryByListWithInfo(BasePage page)
	{
		return dao.queryByListWithInfo(page);
	}

}
